package com.mail.server.service;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mail.dubbo.api.CmsSubjectApi;
import com.mail.model.db.CmsSubject;
import com.mail.model.vo.MyPage;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 吕永乐
 * @date 2022/06/22 21:17
 **/
@Service
public class CmsSubjectService {
	@DubboReference
	private CmsSubjectApi cmsSubjectApi;

	/**
	 * 获取全部商品专题
	 * @return
	 */
	public List<CmsSubject> listAll() {
		List<CmsSubject> cmsSubjects = cmsSubjectApi.getAll();
		if(CollUtil.isEmpty(cmsSubjects)){
			return new ArrayList<>();
		}
		return cmsSubjects;
	}

	/**
	 * 根据专题名称分页获取商品专题
	 * @param pageNum
	 * @param pageSize
	 * @param keyword
	 * @return
	 */
	public MyPage<CmsSubject> listByPage(Long pageNum, Long pageSize, String keyword) {
		Page<CmsSubject> page = cmsSubjectApi.getListByPage(pageNum, pageSize, keyword);
		return MyPage.init(page);
	}
}
